<!DOCTYPE html>
<html>

<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=9; IE=8; IE=7; IE=EDGE">
	<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
	<title>小鸿商城，欢迎登录</title>
	<link rel="icon" href="http://static.xiaohong.work/img/favicon.ico">

    <link rel="stylesheet" type="text/css" href="http://static.xiaohong.work/css/all.css" />
    <link rel="stylesheet" type="text/css" href="http://static.xiaohong.work/css/pages-login.css" />
</head>

<body>
	<!-- 头部栏位 -->
	<!--页面顶部-->
<div id="nav-bottom">
		<!--头部-->
		<div class="header">
			<div class="py-container">
				<div class="yui3-g Logo">
					<div class="">
						<a class="logo-bd" title="商城" href="index.html" target="_blank"></a>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>

	<div class="login-box">

		<!--loginArea-->
		<div class="loginArea">
			<div class="py-container login">
				<div class="loginform">
					<ul class="sui-nav nav-tabs tab-wraped">
						<li id="tabOtherLogin" onclick="switchOtherLogin()">
							<a href="javascript:void(0)" data-toggle="tab" >
								<h3>扫描登录</h3>
							</a>
						</li>
						<li id="tabSuiForm" class="active" onclick="switchSuiForm()">
							<a href="javascript:void(0)" data-toggle="tab" >
								<h3>账户登录</h3>
							</a>
						</li>
					</ul>
					<div class="tab-content tab-wraped">
						<div id="index" class="tab-pane ">
							<p>二维码登录，暂为官网二维码</p>
							<img width="100px" height="100px" style="margin: 0 auto" src="http://static.xiaohong.work/img/xiaohong.png" />
						</div>
						<div id="profile" class="tab-pane active">
							<form class="sui-form">
								<div class="input-prepend"><span class="add-on loginname"></span>
									<input id="inputName" type="text" v-model="user.phone" placeholder="请输入手机号" class="span2 input-xfat">
								</div>
								<div class="input-prepend"><span class="add-on loginpwd"></span>
									<input id="inputPassword" type="password" v-model="user.password" placeholder="请输入密码" class="span2 input-xfat">
								</div>
								<div class="setting">
									<label class="checkbox inline">
										<input name="m1" type="checkbox" value="2" checked="">
										自动登录
									</label>
									<span class="forget">忘记密码？</span>
								</div>
								<div class="logined">
									<a class="sui-btn btn-block btn-xlarge btn-danger" @click="login" target="_blank">登&nbsp;&nbsp;录</a>
								</div>
							</form>
							<div class="otherlogin">
								<div class="types">
									<ul>
										<li><img src="http://static.xiaohong.work/img/qq.png" width="35px" height="35px" /></li>
										<li><img src="http://static.xiaohong.work/img/sina.png" /></li>
										<li><img src="http://static.xiaohong.work/img/ali.png" /></li>
										<li><img src="http://static.xiaohong.work/img/weixin.png" /></li>
									</ul>
								</div>
								<span class="register"><a href="register.html" target="_blank">立即注册</a></span>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
		<!--foot-->
		<end/>
	</div>

<script type="text/javascript">
	function switchSuiForm() {
		document.getElementById('index').className = "tab-pane";
		document.getElementById('profile').className = "tab-pane active";
		document.getElementById('tabSuiForm').className = "active";
		document.getElementById('tabOtherLogin').className = "";
	}
	function switchOtherLogin() {
		document.getElementById('index').className = "tab-pane active";
		document.getElementById('profile').className = "tab-pane";
		document.getElementById('tabSuiForm').className = "";
		document.getElementById('tabOtherLogin').className = "active";
	}
</script>

	<script type="text/javascript" src="http://static.xiaohong.work/js/all.js"></script>
	<script type="text/javascript" src="http://static.xiaohong.work/js/plugins/jquery/jquery.min.js"></script>
	<script type="text/javascript" src="http://static.xiaohong.work/js/pages/index.js"></script>
	<!-- 引入vue -->
	<script src="https://cdn.jsdelivr.net/npm/vue@2.6.12"></script>
	<script src="http://static.xiaohong.work/js/axios.min.js"></script>
	<script src="http://static.xiaohong.work/js/common.js"></script>
	<script>
		new Vue({
			el: '.login-box',
			data() {
				return {
					user: {
						phone: window.localStorage.getItem('phone') || '15279586728', // 登录手机号
						password: '', // 密码
						agree: true, // 是否同意协议
						remember: false // 是否记住密码
					},
					msg: ''
				}
			},
			methods: {
				login(){
					// xiaohong.login()
					xiaohong.http.post("/oauth/user/login",this.user)
					.then(async resp => {
						console.log(resp.data.code)
						if(resp.data.code === 20000){
                            // 保存用户令牌
                            window.localStorage.setItem('accessToken', resp.data.data.body.access_token)
							// 保存用户名
							window.localStorage.setItem('phone', this.user.phone);
                            //获取用户信息
							await this.getUser();
						}
					})
					.catch(() => alert('登录失败'))
				},
				getUser() {
					xiaohong.http.get('/user/phone/'+ window.localStorage.getItem('phone')).then(async resp => {
						if(resp.data.code === 20000){
							// 保存用户信息
							await window.localStorage.setItem('user', JSON.stringify(resp.data.data));
							const url = xiaohong.getUrlParam("returnUrl");
							window.location = url || 'http://www.xiaohong.work';
						}
					}).catch(() => alert('获取用户数据失败'))
				}
			},
			components: {
				top: () => import("http://static.xiaohong.work/js/pages/top.js"),
				end: () => import("http://static.xiaohong.work/js/pages/end.js")
			}
		})
	</script>
</body>
</html>
